package com.yazi.mxz.gather.main;

import java.math.BigDecimal;
import java.util.List;

import com.myframework.smhj.common.tool.DateUtil;
import com.yazi.mxz.gather.common.App;
import com.yazi.mxz.gather.entity.beans.Region;
import com.yazi.mxz.gather.service.RegionService;

/**
 * 更新地区
 * @author mo_yq5
 * @date 2015-9-9
 */
public class RegionUpdate extends Thread {
	
	private RegionService regionService;
	
	
	public RegionUpdate() {
		regionService = App.context.getBean(RegionService.class);
	}

	@Override
	public void run() {
		
		List<Region> list = regionService.list(new Region());
		//list = new ArrayList<Region>();list.add(regionService.oneById(100000L));
		
		for (Region region : list) {
			region.setAds("{"+
			"    \"mob\": ["+
			"        {\"img\": \"http://atta.51mxz.com/tmp/" + new Double(Math.random() * 20).intValue() + ".jpg\", \"url\": \"http://new.m.51mxz.com/storeGoods/detail/58\"},"+
			"        {\"img\": \"http://atta.51mxz.com/tmp/" + new Double(Math.random() * 20).intValue() + ".jpg\", \"url\": \"http://new.m.51mxz.com/storeGoods/detail/543\"},"+
			"        {\"img\": \"http://atta.51mxz.com/tmp/" + new Double(Math.random() * 20).intValue() + ".jpg\", \"url\": \"http://new.m.51mxz.com/storeGoods/detail/158\"}"+
			"    ],"+
			"    \"pc\": ["+
			"        {\"img\": \"http://atta.51mxz.com/tmp/" + new Double(Math.random() * 20).intValue() + ".jpg\", \"url\": \"http://new.m.51mxz.com/storeGoods/detail/5345\"},"+
			"        {\"img\": \"http://atta.51mxz.com/tmp/" + new Double(Math.random() * 20).intValue() + ".jpg\", \"url\": \"http://new.m.51mxz.com/storeGoods/detail/332\"},"+
			"        {\"img\": \"http://atta.51mxz.com/tmp/" + new Double(Math.random() * 20).intValue() + ".jpg\", \"url\": \"http://new.m.51mxz.com/storeGoods/detail/42\"}"+
			"    ]"+
			"}");
			double lat = new BigDecimal((Math.random()*(5333-351) + 351)/100).setScale(6, BigDecimal.ROUND_DOWN).doubleValue();
			double lng = new BigDecimal((Math.random()*(13505-7333) + 7333)/100).setScale(6, BigDecimal.ROUND_DOWN).doubleValue();
			//region.setLatlng(lat + "," + lng);
			region.setCoverType(0);
			//region.setCoverType(3);
			region.setUpdateTime(DateUtil.getTimeStamp());
			region.setWords("{"+
					"    \"mob\": ["+
					"        {\"word\": \"牛肉\", \"url\": \"http://m.51mxz.com/storeGoods/list?searchWord=%E7%89%9B%E8%82%89\"},"+
					"        {\"word\": \"昌鱼\", \"url\": \"http://m.51mxz.com/storeGoods/list?searchWord=%E6%98%8C%E9%B1%BC\"}"+
					"    ],"+
					"    \"pc\": ["+
					"        {\"word\": \"牛肉\", \"url\": \"http://www.51mxz.com/storeGoods/list?searchWord=%E7%89%9B%E8%82%89\"},"+
					"        {\"word\": \"昌鱼\", \"url\": \"http://www.51mxz.com/storeGoods/list?searchWord=%E6%98%8C%E9%B1%BC\"}"+
					"    ]"+
					"}");
			
			regionService.merge(region);
			System.out.println("成功更新: " + region.getName());
		}
	}
	
}
